/*
 * Copyright (c) 2019 Wormpex.com. All Rights Reserved.
 */

package com.sk.agent.javaag;

import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;

/**
 * @author ke.su date: 2019-11-12 Time: 下午3:04
 */
public class TimeStatMethodAdapter extends MethodVisitor implements Opcodes {

    public TimeStatMethodAdapter(MethodVisitor mv) {
        super(Opcodes.ASM5, mv);
    }

    @Override
    public void visitCode() {
        visitMethodInsn(Opcodes.INVOKESTATIC, "com/sk/agent/javaag/Timestat", "start", "()V", Boolean.FALSE);
        super.visitCode();
    }

    @Override
    public void visitInsn(int i) {
        if (i >= IRETURN && i <= RETURN) {
            visitMethodInsn(Opcodes.INVOKESTATIC, "com/sk/agent/javaag/Timestat", "end", "()V", Boolean.FALSE);
        }
        mv.visitInsn(i);
    }
}
